package Gui;

import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;

import GameEngine.GameLogic;
import GameEngine.GameMessage;
import GameEngine.GameSettings;




public class Main {
	boolean reset = false;

	public static void main(String[] args)
	{	
		GameMessage gameMessage = new GameMessage();
		GameLogic core;
		GameGUI mainFrame;
		GameSettingPanel settingPanel;
		boolean newGame =true;
		boolean testMode=true;

		try {
			for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
				if ("Nimbus".equals(info.getName())) {
					UIManager.setLookAndFeel(info.getClassName());
					break;
				}
			}
		} catch (Exception e) {
			JOptionPane.showMessageDialog(null, "Failed Charging Nimbus look And Feel"+"\n"+
									"The application will use Default System Look and Feel");
		}


		while(newGame){

			settingPanel = new GameSettingPanel();

			GameSettings settings=settingPanel.getGameSettings();
			
			while(settings==null){
				settings=settingPanel.getGameSettings();		
				try {
					Thread.sleep(5);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}

			settingPanel = null;

			core = new GameLogic(gameMessage,settings);

			mainFrame = new GameGUI(gameMessage,settings,testMode);

			core.start();

			mainFrame.startGUI();

			if(!settings.isNewGame()){
				System.exit(0);
			}
			core.stop();
			mainFrame = null;

		} 
	}

}
